from expression import expression
import sys
sys.path.append(sys.path[0] + "/../LLVM")
from llvmhelper import llvmHelper
from llvm import *
from commonRoutines import commonRoutines

class varMut(expression):
	def __init__(self, name, value):
		self.name = name
		self.value = value
		self.eframe = None
		
	def evaluate(self, env):
		#print "VarMut: Name: ", self.name.__str__() , " Value: ", self.value
		
		#print "mut env: \n", str(env)
		env.mutateVarRef(self.name.__str__(), self.value.evaluate(env))

	def __str__(self):
		return "varMut(" + str(self.name) + ", " + str(self.value) + ")"
		
	def traverse(self, helper):
		scope = helper.getCurrentScope()
		var = scope.get(self.name)

#		self.eframe = var
		self.eframe = helper.getVar(self.name)
		self.value.traverse(helper)

	def toLLVM(self, helper):
		helper.descend("varMut")
		
		self.value.toLLVM(helper)
		c = commonRoutines(helper)
		
		expValue = helper.getReturns()[0]

		c.setVar(self.eframe[1], self.eframe[2], expValue)
		

		helper.setLabel(helper.getLastLabel())
		helper.ascend(expValue) #what do I do here?
